package com.wyl.auth.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @Description 用户登录日志表
 * @Author WuYiLong
 * @Date 2025-04-13
 */
@Data
@TableName("user_login_log")
@Entity
@Table(name="user_login_log")
@org.hibernate.annotations.Table(appliesTo = "user_login_log",comment = "用户登录日志表")
public class UserLoginLog extends Model<UserLoginLog> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(columnDefinition = "bigint comment '主键id'")
    private Long id;

    @Column(columnDefinition = "bigint comment '关联用户表id'")
    private Long userId;

    @Column(columnDefinition = "datetime comment '登录时间'")
    private LocalDateTime loginTime;

    @Column(columnDefinition = "varchar(200) comment '登录ip'")
    private String ipAddress;

    @Column(columnDefinition = "varchar(255) comment '浏览器/设备信息'")
    private String userAgent;

    @Column(columnDefinition = "tinyint comment '0=失败, 1=成功'")
    private Integer loginResult;

    @Column(columnDefinition = "varchar(255) comment '失败原因'")
    private String failureReason;

    @Column(columnDefinition = "varchar(100) comment '设备类型'")
    private String deviceType;

    @Column(columnDefinition = "varchar(100) comment '地理位置'")
    private String location;

    @Column(columnDefinition = "varchar(255) comment '会话ID'")
    private String sessionId;

    @Column(columnDefinition = "varchar(255) comment '国家'")
    private String country;
    @Column(columnDefinition = "varchar(255) comment '省份'")
    private String province;
    @Column(columnDefinition = "varchar(255) comment '城市'")
    private String city;

    @Override
    public Serializable pkVal() {
        return this.id;
    }

}
